package com.xgkj.diyiketang.task;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xgkj.diyiketang.data.EatShowUserInfo;
import com.xgkj.diyiketang.http.CouponHttpRequest;
import com.xgkj.diyiketang.http.CouponHttpResponse;
import com.xgkj.diyiketang.http.engine.CouponHttpBaseTask;
import com.xgkj.diyiketang.http.engine.TaskResultCode;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by windo on 16/8/17.
 */
public class GetParentListTask extends CouponHttpBaseTask{
    @Override
    protected void processResponseData(CouponHttpResponse response) {
        JSONObject jsonObject = response.getBody();
        List<EatShowUserInfo> list = new ArrayList<EatShowUserInfo>();
        if (jsonObject != null){
           String familylist =  jsonObject.getString("familyList");
            if (familylist != null){
                list = JSON.parseArray(familylist,EatShowUserInfo.class);
            }
        }
        notifyTaskCompleted(TaskResultCode.SUCCESS,list);
    }

    public GetParentListTask() {
        super();
    }

    @Override
    protected void prepareRequest() {
        super.prepareRequest();
        if (mPhase == TASK_PHASE_INIT){
            CouponHttpRequest request = new CouponHttpRequest();
            request.setApiNo(ApiNo.PARENTLIST);
            addRequest(request);
        }
    }
}
